﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using LinQ_DTO;
using BUS;
using System.Xml;

namespace TemplateH4
{
    public partial class Register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void Page_PreInit(object sender, EventArgs e)
        {
            String thm;
            thm = (string)Session["themeSelected"];
            if (thm != null)
            {
                Page.Theme = thm;
            }
            else
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(Server.MapPath("~/config.xml"));
                XmlNode root = doc.DocumentElement;
                String theme = root.SelectSingleNode("theme").ChildNodes[0].Value.Trim();
                Session.Add("themeSelected", theme);
                Page.Theme = theme;
            }

        }



        protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
        {
            MembershipUser User = Membership.GetUser(CreateUserWizard1.UserName);
            Guid UserID = (Guid) User.ProviderUserKey;

            MembershipBUS memBus = new MembershipBUS();
            aspnet_Membership mem = memBus.LayTheoUserId(UserID);

            TextBox textbox;
            textbox = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtDienThoai");
            mem.DTDD = textbox.Text;
            textbox = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtDiaChi");
            mem.DiaChi = textbox.Text;
            textbox = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtMes");
            mem.YahooYM = textbox.Text;
            textbox = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtWebsite");
            mem.Website = textbox.Text;
            
            memBus.CapNhat(mem);

            UsersInRoleBUS UserRoleBus = new UsersInRoleBUS();
            RoleBUS RoleBus = new RoleBUS();
            aspnet_UsersInRole UserRole = new aspnet_UsersInRole();
            aspnet_Role Role = new aspnet_Role();

            Role = RoleBus.LayRoleTheoLoweredRoleName("customer");
            UserRole.UserId = UserID;
            UserRole.RoleId = Role.RoleId;
            UserRoleBus.Them(UserRole);
            
  
        }
    }
}
